package uutalk.netcloud.talk.base.mqtt.model;

import org.eclipse.paho.client.mqttv3.MqttMessage;

import uutalk.netcloud.talk.base.util.TimeUtil;


/**
 * ClassName: Publication
 * Desc:
 * Created by zhiw on 2017/3/23.
 */

public class Publication  {

    private String topic;

    private String payload;

    private
    @QoSConstant.QoS
    int QoS;

    private boolean isRetained;

    private String time;


    public Publication(String topic, String payload, int qoS, boolean isRetained) {
        this.topic = topic;
        this.payload = payload;
        QoS = qoS;
        this.isRetained = isRetained;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getPayload() {
        return payload;
    }

    public void setPayload(String payload) {
        this.payload = payload;
    }

    public int getQoS() {
        return QoS;
    }

    public void setQoS(int qoS) {
        QoS = qoS;
    }

    public boolean isRetained() {
        return isRetained;
    }

    public void setRetained(boolean retained) {
        isRetained = retained;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public void setTime() {
        this.time = TimeUtil.formatNow();
    }



    public MqttMessage getMessage() {
        MqttMessage message = new MqttMessage();
        message.setPayload(payload.getBytes());
        message.setQos(QoS);
        message.setRetained(isRetained());
        return message;
    }


}
